package org.example.demo.test6;

public class GoodsTest {
    public static void main(String[] args) {
        Goods[] arr = new Goods[3];
       Goods goods1 =  new Goods("001", "华为手机",100.002,20);
       Goods goods2 =  new Goods("002", "华为手机",100.002,30);
       Goods goods3 =  new Goods("003", "保温杯",100.002,50);

       arr[0] = goods1;
       arr[1] = goods2;
       arr[2] = goods3;
        /*
        需求1: 再次添加学生对象, 并且添加的时候进行唯一判断, 如果数组已满,就进行扩容. 长度加一.
        */
        Goods goods4 =  new Goods("004", "学生4",100.002,50);
        boolean isCon = isContaioner(arr,goods4.getId());

        /*
        需求2: 删除指定id学生信息, 存在删除.不存在报错
        */
        /*
        * 需求三, 查询制定id
        * */

    }
    public static Integer getCount(Goods[] arr){
        int count =0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] != null)count++;
        }
        return  count;
    }
    public static Goods[] createNewArr(Goods[] arr){
        Goods[] newArr = new Goods[arr.length + 1];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }
        return  newArr;
    }
    public static Boolean isContaioner(Goods[] arr,String id){
        boolean count = false;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i].id.equals(id)){
                count = true;
                break;
            }
        }
        return  count;
    }
}
